#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int res=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=(res<<1)+(res<<3)+(c^48);c=getchar();}
	return res*f;
}
void write(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);
	putchar(x%10+'0');
}
struct node
{
	int nxt,to,id;
}e[1000005<<1];
int head[1000005],cnt_edge;
void add_edge(int u,int v,int id)
{
	e[++cnt_edge].to=v;
	e[cnt_edge].id=id;
	e[cnt_edge].nxt=head[u];
	head[u]=cnt_edge;
}
struct edge
{
	int u,v,w;
}a[1000005];
int n;
int sum1[1000005],sum2[1000005],sum3[1000005];
int son[1000005],f[1000005],top[1000005],siz[1000005],dfn[1000005];
int cnt;
int ans[1000005],sum;
int id[1000005],rt[1000005];
void dfs1(int u,int fa)
{
	siz[u]=1;f[u]=fa;
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==fa) continue;
		id[v]=e[i].id;rt[v]=rt[u];
		dfs1(v,u);
		siz[u]+=siz[v];
		if(siz[son[u]]<siz[v]) son[u]=v;
	}
}
void dfs2(int u,int t)
{
	top[u]=t;dfn[u]=++cnt;
	if(son[u]) dfs2(son[u],t);
	for(int i=head[u];i;i=e[i].nxt)
	{
		int v=e[i].to;
		if(v==f[u]||v==son[u]) continue;
		dfs2(v,v);
	}
}
void update(int u)
{
	int x=u;
	if(u==rt[u]) return;
	u=f[u];
	while(top[u]!=rt[u])
	{
		sum3[dfn[top[u]]]+=siz[x];sum3[dfn[u]+1]-=siz[x];
		sum1[dfn[top[u]]]-=siz[x];sum1[dfn[u]+1]+=siz[x];
		u=f[top[u]];
	}
	sum3[dfn[rt[u]]]+=siz[x];sum3[dfn[u]+1]-=siz[x];
	sum1[dfn[rt[u]]]-=siz[x];sum1[dfn[u]+1]+=siz[x];
}
signed main()
{
	freopen("tatooine.in","r",stdin);
	freopen("tatooine.out","w",stdout);
	n=read();
	for(int i=1;i<n;i++) a[i].u=read(),a[i].v=read(),a[i].w=read();
	for(int i=20;i>=1;i--)
	{
		cnt_edge=0;
		for(int j=1;j<=n;j++) head[j]=0;
		for(int j=1;j<=n;j++)
			if(a[j].w>=i) add_edge(a[j].u,a[j].v,j),add_edge(a[j].v,a[j].u,j);
		for(int j=1;j<=n;j++) f[j]=son[j]=top[j]=rt[j]=id[j]=sum1[j]=sum2[j]=sum3[j]=siz[j]=dfn[j]=0;
		cnt=0;
		for(int j=1;j<=n;j++) if(!rt[j]) rt[j]=j,dfs1(j,0);
		for(int j=1;j<=n;j++) if(j==rt[j]) dfs2(j,j);
		for(int j=1;j<=n;j++)
			if(a[id[j]].w==i) 
			{
				sum+=i*siz[j]*(siz[rt[j]]-siz[j]);
				sum1[dfn[rt[j]]]+=siz[j];sum1[dfn[j]]-=siz[j];
				sum1[dfn[j]+siz[j]]+=siz[j];sum1[dfn[rt[j]]+siz[rt[j]]]-=siz[j];
				sum2[dfn[j]]+=(siz[rt[j]]-siz[j]);sum2[dfn[j]+siz[j]]-=(siz[rt[j]]-siz[j]);
				update(j);
			}
		for(int j=1;j<=n;j++) sum1[j]+=sum1[j-1],sum2[j]+=sum2[j-1],sum3[j]+=sum3[j-1];
		for(int j=1;j<=n;j++)
			ans[id[j]]+=(sum1[dfn[j]]+sum2[dfn[j]])*siz[j]*i+sum3[dfn[j]]*(siz[rt[j]]-siz[j])*i;
	}
//	cout<<sum<<endl;
	for(int i=1;i<n;i++) write(sum-ans[i]),puts("");
	return 0;
}
